<?php

/*
Give or Take Discount (admin_discount_cards.pro.php)
*/

$page_title = "Give/Take Discount";
$rank_check = 7;
include "../global.inc.php";

$points_username = strtolower(ereg_replace(" ", "", $points_username));
$findUsername = fetch("SELECT * FROM members2 WHERE username = '$points_username' AND game = '$game'");

$discount_percent2 = $discount_percent / 100;

$findDiscount = fetch("SELECT * FROM discount_cards WHERE user = '$findUsername[id]' AND game = '$game'");
if (!$findDiscount[discount]) { $findDiscount[discount] = 0; }

if ($give_take == "give")
{
	$newRate = $findDiscount[discount] + $discount_percent2;
	$words = "added $discount_percent% to";
	$discount_percent3 = $discount_percent;
}
if ($give_take == "take")
{
	$newRate = $findDiscount[discount] - $discount_percent2;
	$words = "taken $discount_percent% from";
	$discount_percent3 = "-$discount_percent";
}
$newRate2 = $newRate * 100;

if ($newRate < 0) { $newRate = 0; }
if ($newRate > 1) { $newRate = 1; }

if ($findDiscount[id])
{	
	mysql_query("UPDATE discount_cards SET discount = $newRate WHERE user = '$findUsername[id]' AND game = '$game'");
	mysql_query("UPDATE discount_cards SET reasons = '$findDiscount[reasons], $reward_reason - $discount_percent3%' WHERE user = '$findUsername[id]' AND game = '$game'");
}
if (!$findDiscount[id])
{
	mysql_query("INSERT INTO discount_cards (game,user,discount,reasons) VALUES ('$game','$findUsername[id]','$newRate',', $reward_reason - $discount_percent3%')");
}

$discount2 = $findDiscount[discount] * 100;

systemmessage("$game", "", "$findUsername[id]", "An admin has $words your discount card for $reward_reason!!");

header(error("admin_discount_cards.php?game=$game","$points_username discount card has been changed from $discount2% to $newRate2%"));

?>
